package com.lex.samismyfather;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentTransaction;

import com.lex.widget.FooterNavBar;
import com.lex.widget.text_view.CustomFontTextView;

public class MainFragmentActivity extends FragmentActivity {

    private FooterNavBar footerNavBar;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main_fragment);
        findView();
        initView();
    }

    private void findView(){
        footerNavBar = (FooterNavBar) findViewById(R.id.footer_nav_bar);
    }

    private void initView(){
        footerNavBar.setOnNavItemChangedListener(onNavItemChangedListener);
    }

    private void showFragment(Fragment fragment){
        FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
        fragmentTransaction.replace(R.id.content,fragment);
        fragmentTransaction.commit();
    }

    protected FooterNavBar.OnNavItemChangedListener onNavItemChangedListener = new FooterNavBar.OnNavItemChangedListener() {
        private static final int FIRST_TAB = 0;
        private static final int SECOND_TAB = 1;
        private static final int THIRD_TAB = 2;
        private static final int FOURTH_TAB = 3;

        @Override
        public void onNavItemChanged(CustomFontTextView[] items, CustomFontTextView item, int position) {
            for(int i = 0; i < 4; i++) items[i].setAlpha(0.5f);
            switch (position){
                case FIRST_TAB:
                    showFragment(ScanFragment.getInstance());
                    item.setAlpha(1.0f);
                    break;
                case SECOND_TAB:
                    showFragment(HistoryFragment.getInstance());
                    item.setAlpha(1.0f);
                    break;
                case THIRD_TAB:
                    showFragment(MadeFragment.getInstance());
                    item.setAlpha(1.0f);
                    break;
                case FOURTH_TAB:
                    showFragment(SettingsFragment.getInstance());
                    item.setAlpha(1.0f);
                    break;
            }
        }
    };
}